#include "prop.h"
#include <stdlib.h>

prop *CreateProp(enum PropType type, void *ptr)
{
    prop *p = (prop*)malloc(sizeof(prop));
    if(p == NULL)
    {
        return NULL;
    }
    p->type = type;
    p->ptr = ptr;
    return p;
}

void FreeProp(void *p, void (*ClearPtr)(void *))
{
    prop *pro = (prop*)p;
    ClearPtr(pro->ptr);
    free(pro);
}

weapon *CreateWeapon(const char *name, int ATK, enum Effect effect)
{
    weapon *w = (weapon*)malloc(sizeof(weapon));
    if(w == NULL)
    {
        return NULL;
    }
    w->ATK = ATK;
    w->effect = effect;
    w->name = GetString(name);
    return w;
}

void FreeWeapon(void *ptr)
{
    weapon *w = (weapon*)ptr;
    ClearString(&w->name);
    free(w);
}

defence *CreateDefence(const char *name,int def,enum Effect effect)
{
    defence *d = (defence*)malloc(sizeof(defence));
    if(d == NULL)
    {
        return NULL;
    }
    d->effect = effect;
    d->def = def;
    d->name = GetString(name);
    return d;
}

void FreeDefence(void *ptr)
{
    defence *d = (defence*)ptr;
    ClearString(&d->name);
    free(d);
}

medicament *CreateMedicament(const char *name, int HP,enum Effect effect)
{
    medicament *m = (medicament*)malloc(sizeof(medicament));
    if(m == NULL)
    {
        return NULL;
    }
    m->effect = effect;
    m->HP = HP;
    m->name = GetString(name);
    return m;
}

void FreeMedicament(void *ptr)
{
    medicament *m = (medicament*)ptr;
    ClearString(&m->name);
    free(m);
}
